<?php
$uid = $_G['uid'];

if(empty($uid)){
    message('请先登录');
}

$table_er_kami_apibuy_log = C::t('#erling_kami_apibuy#er_kami_apibuy_log');

$url_page = 'home.php?mod=spacecp&ac=plugin&id=erling_kami_apibuy:user_kami';

$page = max($_GET['page']??1, intval($page));
$pagesize = max($_GET['pagesize']??10, intval($pagesize));

$query = [
    'uid' => $uid,
    'status' => 2,
];
if(!empty($_GET['kami_key'])){
    $query['kami_key'] = trim($_GET['kami_key']);
    $url_page .= '&kami_key='.urlencode($_GET['kami_key']);
}
if(!empty($_GET['title'])){
    $query['title'] = trim($_GET['title']);
    $url_page .= '&title='.$_GET['title'];
}
$result = $table_er_kami_apibuy_log->fetch_all($page, $pagesize, $query, -1);
$kami_list = $result['data'];
$total = $result['total'];
if(!empty($_GET['pagesize'])){
    $url_page .= '&pagesize='.intval($_GET['pagesize']);
}
$multipage = multi($total, $pagesize, $page, $url_page);

// 积分类型
$extcredits_array = DB::fetch_all("SELECT * FROM %t WHERE skey LIKE %s", array('common_setting', 'extcredits%'));
if ($extcredits_array && isset($extcredits_array[0]['svalue'])) {
    $extcredits_data = unserialize($extcredits_array[0]['svalue']);
} else {
    $extcredits_data = [];
}